package com.api.demo.test.pay_centre;

import com.alibaba.fastjson.JSON;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: ym
 * @Description: 平安银行
 * @Date: 2024/2/19 10:57
 * @Version: 1.0
 */
public class Pa extends Common {
    public static String requestUrl = "http://127.0.0.1:10009/api/pay/pa/";

//智能收款测试-智能收款测试数据:C001, C002, C003, C004, C005, C006, C007, C008, C009
//    public static String bankApplicationId = "00901080000008888000"; //银行应用ID （用户uid）
//    public static String accountNo = "15000100716415"; //银行账户号  （银行一般户）


    //普通业务测试-普通业务测试数据: 4001, 4002, 4004, 4005, 4006, 4008, 4011, 4012, 4013, 4014, 4015, 4017, 4018, 4019,400101
    public static String bankApplicationId = "00901080000008888000"; //银行应用ID （用户uid）
    public static String accountNo = "15000100716512"; //银行账户号  （银行一般户）


    public static void main(String[] args) {
        //智能清分台账编码关系查询[C001]
//        post(requestUrl+"/c001", c001());

        //清分台账编码维护和权限同步（AUDR）[C002]
//        post(requestUrl + "/c002", c002());

//        //查询交易流水
//        post(requestUrl+"/c006", c006());
//
//        //清分台账编码余额查询
//        post(requestUrl+"/c008", c008());
//
//        //查询子账户充值交易流水
//        post(requestUrl + "/c00602", c00602());
//
//        //3.14转账对手白名单维护[C011]
//        post(requestUrl+"/c011", c011());
//
//        //银行联行号查询
//        post(requestUrl + "/tp4017", tp4017());
//
//        //3.2企业账户余额查询 [4001]
//        post(requestUrl + "/query4001", query4001());

        //单笔转账-下发单笔转账
//        post(requestUrl + "transfer", transfer());

        //单笔转账-内部转账
//        post(requestUrl + "transfer", interior_transfer());

        //批量交易
        post(requestUrl + "transferBatch", transferBatch());


    }


    /**
     * 智能清分台账编码关系查询[C001]
     */
    public static String c001() {
        Map<String, Object> data = new HashMap<>();
        data.put("bankApplicationId", bankApplicationId);

        data.put("mainAccount", accountNo);
        data.put("ccyCode", "");
        data.put("reqSubAccountNo", "0"); //第一次查询，输入0，否则输入返回最后一笔的智能清分台账编码进行分页查询
        data.put("pageNo", "100");

        return encrypt(data);
    }


    /**
     * 清分台账编码维护和权限同步（AUDR）[C002]
     */
    public static String c002() {
        Map<String, Object> data = new HashMap<>();
        data.put("bankApplicationId", bankApplicationId);

        data.put("mainAccount", accountNo);
        data.put("ccyCode", "");
        data.put("subAccountSeq", Zs.random(6));
        data.put("subAccount", "");
        data.put("subAccountName", "test");
        data.put("subAccountNameEn", "test");
        data.put("opFlag", "A");
        data.put("oDFlag", "N");
        data.put("interestFlag", "N");
//        data.put("settleInterestCycle", "Q"); 建议不填使用默认值， 默认值：Q，不可更改
//        data.put("rate", "");
//        data.put("zSZFStatus", "");   30206465373892
        //30206465373892
        return encrypt(data);
    }


    /**
     * 查询交易流水
     */
    public static String c006() {
        Map<String, Object> data = new HashMap<>();
        data.put("bankApplicationId", bankApplicationId);

        data.put("mainAccount", accountNo);
        data.put("opFlag", "1");
        data.put("reqSubAccountNo", "");
        data.put("startDate", "20240101");
        data.put("endDate", "20240201");
        data.put("reqLastSubAccNo", "0");
        data.put("reqLastDate", "0");
        data.put("reqLastJNo", "0");
        data.put("reqLastSeq", "0");
//        data.put("hostFlowNo", "");
        data.put("pageSize", "100");

        return encrypt(data);
    }

    /**
     * 清分台账编码余额查询
     */
    public static String c008() {
        Map<String, Object> data = new HashMap<>();
        data.put("bankApplicationId", bankApplicationId);

        data.put("mainAccount", accountNo);
        data.put("ccyCode", "");
        data.put("reqSubAccountNo", "30206466771648");

        return encrypt(data);
    }

    /**
     * 查询子账户充值交易流水
     */
    public static String c00602() {
        Map<String, Object> data = new HashMap<>();
        data.put("bankApplicationId", bankApplicationId);

        data.put("mainAccount", accountNo);
        data.put("opFlag", "1");
        data.put("dcFlag", "C");
        data.put("reqSubAccount", "");
        data.put("startTime", "20240101000000");
        data.put("endTime", "20240201000000");
        data.put("pageNo", "1");
        data.put("pageSize", "10");

        return encrypt(data);
    }


    /**
     * 3.14转账对手白名单维护[C011]
     */
    public static String c011() {
        Map<String, Object> data = new HashMap<>();
        data.put("bankApplicationId", bankApplicationId);

        data.put("mainAccount", accountNo);
        data.put("validationFlag", "");
        data.put("functionCode", "A");

        List<Map<String, Object>> tranItemArray = new ArrayList<>();

        Map<String, Object> tranItem = new HashMap<>();
        tranItem.put("signAcctNo", "30206465373892");
        tranItem.put("ccy", "");
        tranItem.put("checkType", "2");
        tranItem.put("whiteListType", "3");
        tranItem.put("counterpartyAcctNo", "");
        tranItem.put("drcrFlag", "");
        tranItem.put("counterpartyAcctName", "某某有限公司2222");
        tranItem.put("counterpartyOpenBranchID", "");
        tranItemArray.add(tranItem);
        data.put("tranItemArray", tranItemArray);

        return encrypt(data);
    }

    /**
     * 银行联行号查询
     */
    public static String tp4017() {
        Map<String, Object> data = new HashMap<>();
        data.put("bankApplicationId", bankApplicationId);

        data.put("bankName", "招商银行");
        data.put("accountNo", "6214851203618397");

        return encrypt(data);
    }


    /**
     * 3.2企业账户余额查询 [4001]
     */
    public static String query4001() {
        Map<String, Object> data = new HashMap<>();
        data.put("bankApplicationId", bankApplicationId);

        data.put("account", accountNo);
        data.put("ccyType", "");
        data.put("ccyCode", "");

        return encrypt(data);
    }


    /**
     * 单笔转账-下发单笔转账
     *
     * @return
     */
    private static String transfer() {
        Map<String, Object> d1 = new HashMap<>();
        long orderNo = System.currentTimeMillis();
        System.out.println("订单号:" + orderNo);
        d1.put("bankApplicationId", bankApplicationId);
        d1.put("businessOrderId", orderNo); //测试使用 实际需输入唯一的订单号
        d1.put("businessSubOrderId", "");

        d1.put("amount", new BigDecimal("1.32"));
        d1.put("remarks", "我是备注");
//        d1.put("remarks", "我是备注1234124141234123131312");
        d1.put("businessTag", "");
        d1.put("businessCallbackUrl", "");
        d1.put("accountIdCardTo", "");
        Map<String, BigDecimal> linkedHashMap = null;

//        linkedHashMap = new LinkedHashMap<>();
//        linkedHashMap.put("PAYEE_MONTH", new BigDecimal("9.99"));//PAYEE_MONTH("PAYEE_MONTH", "收款方月限额"),
//        linkedHashMap.put("PAYEE_YEAR", new BigDecimal("99.99"));//PAYEE_YEAR("PAYEE_YEAR", "收款方年限额"),
//
        d1.put("amountLimitDto", linkedHashMap); //限额信息
        d1.put("parkId", "");
        d1.put("accountNumberFrom", "30206466771648");
        d1.put("accountOwnerFrom", "测试商户");

        //内部转账
//        d1.put("tradeChannel", 1011);  //1011 内部转账（子账户转账） 、 1012 银行卡下发）
//        d1.put("accountNumberTo", "6468235474");
//        d1.put("accountOwnerTo", "测试商户");

        //银行卡下发
        d1.put("tradeChannel", 1001);  //1002 内部转账（子账户转账） 、 1001 银行卡下发）
        d1.put("accountNumberTo", "6230580000054508325");
        d1.put("accountOwnerTo", "祖起");

        d1.put("sameBank", true);
        d1.put("bankNodeTo", "");

//        //主账户信息
//        Map<String, Object> mainAccountDto = new HashMap<>();
//        mainAccountDto.put("mainAccount", accountNo);
//        mainAccountDto.put("mainAccountName", "测试");
        d1.put("mainAccountDto", getMainAccount());

        return encrypt(d1);
    }


    /**
     * 单笔转账-内部转账
     */
    private static String interior_transfer() {
        Map<String, Object> d1 = new HashMap<>();
        long orderNo = System.currentTimeMillis();
        System.out.println("订单号:" + orderNo);
        d1.put("bankApplicationId", bankApplicationId);
        d1.put("businessOrderId", orderNo); //测试使用 实际需输入唯一的订单号
        d1.put("businessSubOrderId", "");

        d1.put("amount", new BigDecimal("10000.32"));
        d1.put("remarks", "我是备注");
        d1.put("businessTag", "");
        d1.put("businessCallbackUrl", "");
        d1.put("accountIdCardTo", "");

        d1.put("amountLimitDto", null); //限额信息
        d1.put("parkId", "");
        d1.put("accountNumberFrom", "30006466000000");
        d1.put("accountOwnerFrom", "测试商户");

        //内部转账
        d1.put("tradeChannel", 1002);  //1002 内部转账（子账户转账） 、 1001 银行卡下发）
        d1.put("accountNumberTo", "30206466771648");
        d1.put("accountOwnerTo", "测试商户");


        d1.put("sameBank", true);
        d1.put("bankNodeTo", "");

        //主账户信息
//        Map<String, Object> mainAccountDto = new HashMap<>();
//        mainAccountDto.put("mainAccount", accountNo);
//        mainAccountDto.put("mainAccountName", "测试");
        d1.put("mainAccountDto", getMainAccount());

        return encrypt(d1);
    }


    /**
     * 批量转账
     *
     * @return
     */
    private static String transferBatch() {

        Map<String, Object> d1 = new HashMap<>();
        d1.put("bankApplicationId", bankApplicationId);

        //批量明细
        List<Map<String, Object>> transferDtoList = new ArrayList<>();

        long orderNo = System.currentTimeMillis();
        System.out.println("订单号:" + orderNo);

        //限额信息
        Map<String, BigDecimal> linkedHashMap = null;
//        linkedHashMap = new LinkedHashMap<>();
//        linkedHashMap.put("PAYEE_MONTH", new BigDecimal("9.99"));//PAYEE_MONTH("PAYEE_MONTH", "收款方月限额"),
//        linkedHashMap.put("PAYEE_YEAR", new BigDecimal("99.99"));//PAYEE_YEAR("PAYEE_YEAR", "收款方年限额"),
//


//        批量基础信息
        Map<String, Object> batchBaseInfoDto = new HashMap<>();
        batchBaseInfoDto.put("businessBatchId", orderNo);
        batchBaseInfoDto.put("thirdMerchantCode", bankApplicationId);
        batchBaseInfoDto.put("tradeChannel", 1001);
        batchBaseInfoDto.put("accountNumberFrom", "30206466771648");
        batchBaseInfoDto.put("accountOwnerFrom", "测试商户");
        batchBaseInfoDto.put("totalAmount", new BigDecimal("20.24"));
        batchBaseInfoDto.put("totalNum", 2);
        batchBaseInfoDto.put("remarks", "测试款");
        batchBaseInfoDto.put("parkId", "1");

        d1.put("batchBaseInfoDto", batchBaseInfoDto); //  批量基础信息


        //主账户信息
//        Map<String, Object> mainAccountDto = new HashMap<>();
//        mainAccountDto.put("mainAccount", accountNo);
//        mainAccountDto.put("mainAccountName", "测试");
//        mainAccountDto.put("branchNo", bankBranchCode); //招商银行必填
        d1.put("mainAccountDto", getMainAccount()); //  主账户信息


        //下发人员1
        Map<String, Object> transferDto = new HashMap<>();
        transferDto.put("businessOrderId", orderNo + 11);
        transferDto.put("businessSubOrderId", orderNo + 1);
        transferDto.put("thirdMerchantCode", bankApplicationId);
        transferDto.put("tradeChannel", 1001);
        transferDto.put("amount", new BigDecimal("10.12"));
        transferDto.put("remarks", "灵活用工费用结算");
//        transferDto.put("businessTag", "");
//        transferDto.put("businessCallbackUrl", "");
        transferDto.put("accountIdCardTo", "123123123123");
        transferDto.put("amountLimitDto", linkedHashMap);
        transferDto.put("parkId", "1");
        transferDto.put("accountNumberTo", "6225380092315250");
        transferDto.put("accountOwnerTo", "钭旨");
        transferDto.put("accountNumberFrom", "30206466771648");
        transferDto.put("accountOwnerFrom", "测试商户");
        transferDto.put("sameBank", true); //招商、平安 需要提供
        transferDto.put("bankNodeTo", "");
        transferDto.put("mainAccountDto", getMainAccount());
        transferDtoList.add(transferDto);
        // ---------------  ---------------


        //下发人员1
        Map<String, Object> transferDto1 = new HashMap<>();
        transferDto1.put("businessOrderId", orderNo + 12);
        transferDto1.put("businessSubOrderId", orderNo + 2);
        transferDto1.put("thirdMerchantCode", bankApplicationId);
        transferDto1.put("tradeChannel", 1001);
        transferDto1.put("amount", new BigDecimal("10.12"));
        transferDto1.put("remarks", "灵活用工费用结算");
//        transferDto.put("businessTag", "");
//        transferDto.put("businessCallbackUrl", "");
        transferDto1.put("accountIdCardTo", "123123123123");
        transferDto1.put("amountLimitDto", linkedHashMap);
        transferDto1.put("parkId", "1");
        transferDto1.put("accountNumberTo", "6230580000054508325");
        transferDto1.put("accountOwnerTo", "祖起");
        transferDto1.put("accountNumberFrom", "30206466771648");
        transferDto1.put("accountOwnerFrom", "测试商户");
        transferDto1.put("sameBank", true); //招商、平安 需要提供
        transferDto1.put("bankNodeTo", "");
        transferDto1.put("mainAccountDto", getMainAccount());
        transferDtoList.add(transferDto1);
        // ---------------  ---------------


        //批量明细
        d1.put("transferDtoList", transferDtoList);

        return encrypt(d1);
    }


    public static Map<String, Object> getMainAccount() {
        Map<String, Object> mainAccountDto = new HashMap<>();
        mainAccountDto.put("mainAccount", accountNo);
        mainAccountDto.put("mainAccountName", "测试");
        return mainAccountDto;
    }


}
